#pragma once
#include<iostream>
#include<pthread.h>

class Lock
{
public:
    Lock(pthread_mutex_t* t)
    :_t(t)
    {}
    int lock()
    {
        return pthread_mutex_lock(_t);
    }

    int unlock()
    {
        return pthread_mutex_unlock(_t);
    }
private:
    pthread_mutex_t* _t;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* l)
    :_l(l)
    {
        _l.lock();
    }

    ~LockGuard()
    {
        _l.unlock();
    }

private:
    Lock _l;
};